﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ccit.OA.Utils;
namespace Ccit.OA.Scheduler
{
    public partial class scheduler_Search_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidTabId.Value = (null != Request.QueryString["TABID"]) ? Request.QueryString["TABID"].ToString() : "";
                _hidQuery.Value = (Request.QueryString["Query"] != null) ? Request.QueryString["Query"].ToString() : "";
                ViewState["Query"] = "";
            }
            InitPage(); 
        }
        private void InitPage()
        {
            if (_hidQuery.Value != "")
            { 
                string pageSQl = "1=1";
                if (_hidTabId.Value != "")
                {
                    pageSQl = SysInterface.GetPageDataRangeSQL("SCH_A1", _hidTabId.Value);
                   
                }
                ViewState["Query"] = pageSQl+"_"+_hidQuery.Value; 
            }
            DataBinde();
        }
        /// <summary>
        /// 绑定GRID
        /// </summary>
        private void DataBinde()
        {
            SchedulerBLL Bll = new SchedulerBLL();
            DataSet dSet = Bll.GetSchedulerMes(ViewState["Query"].ToString());
            Bll = null;
            if(dSet.Tables[0].Rows.Count>0)
            {
                gvSchList.DataSource = dSet;
            }
            else
            {
                gvSchList.DataSource = null;
            }
            gvSchList.DataBind();          
        }
        protected void gvSchList_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
            string Complete = gvSchList.GetRowValues(e.VisibleIndex, "Complete").ToString();
            string SchClass = gvSchList.GetRowValues(e.VisibleIndex, "SchClass").ToString();
            string userId = gvSchList.GetRowValues(e.VisibleIndex, "UserID").ToString();
            if (Complete == "0")
            { e.Row.Cells[0].Text = "未完成"; }
            else
            { e.Row.Cells[0].Text = "已完成"; }
            if (SchClass == "0" || SchClass == null)
            {
                e.Row.Cells[5].Text = "个人日程";
            }
            else
            {
                e.Row.Cells[5].Text = "代理日程";
            }
            //string userName = SysInterface.GetNameStrByIdStr(userId, NameType.USER, "");
            //e.Row.Cells[2].Text = (userName!="")?userName:"&nbsp;";
        }

        protected void lnbQuery_Click(object sender, EventArgs e)
        {
            ViewState["Query"] = "";
            InitPage(); 
        }
    }
}
